package flextestng.testing.utils
{
	import flash.utils.describeType;
	import flash.utils.getQualifiedClassName;
	
	public class ClassUtils
	{
		/**
		 * Finds the public methods for the specified class.  A call to this function 
		 * does not return any methods of its super class.
		 * 
		 * @param clazz The class.
		 * @return All public methods for the given class.
		 */
		public static function getClassMethods(clazz:Class):XMLList
		{
			var name:String = getQualifiedClassName(clazz);
			var definition:XML = describeType(clazz);
			return definition..method.(@declaredBy == name);
		}
		
		/**
		 * Finds the public class methods that have the given metatag. A call to this 
		 * function does not return any methods of its super class.
		 * 
		 * @param clazz The class to search on.
		 * @param metatag The case-sensitive metatag to find.
		 * @return All the public methods that contain this metatag.
		 */		
		public static function getMethodsForMetatag(clazz:Class, metatag:String):Array
		{
			var classMethods:XMLList = getClassMethods(clazz);
			var methods:Array = [];
			
			for each (var method:XML in classMethods) {
				var metatags:XMLList = method.metadata;
				
				for each (var tag:XML in metatags) {
					if (tag.@name == metatag) {
						methods.push(method);
						break;
					}
				}
			}
			
			return methods;
		}
	}
}